import os
import shutil

length = int(2560 / 5)
width = int(1440 / 5)


def cut_pictures():
    count = 0
    for i in range(5):
        for j in range(5):
            count += 1
            command = 'ffmpeg -i ./skiing.png -vf crop=' + str(length) + ':' + str(width) + ':' + \
                      str(length * j) + ':' + str(width * i) + ' -y ./cut_files/' + str(count) + '.png'
            print(command)
            os.system(command)


def combine_pictures():
    os.makedirs('./fov_tiles/', exist_ok=True)
    os.makedirs('./out_fov_tiles/', exist_ok=True)
    fov_list = [8, 9, 10, 13, 14, 15]
    count = 1
    for i in range(5):
        for j in range(5):
            if count in fov_list:
                shutil.copy('./cut_files/' + str(count) + '.png', './fov_tiles/' + str(count) + '.png')
                shutil.copy('./cut_files/black.png', './out_fov_tiles/' + str(count) + '.png')
            else:
                shutil.copy('./cut_files/' + str(count) + '.png', './out_fov_tiles/' + str(count) + '.png')
                shutil.copy('./cut_files/black.png', './fov_tiles/' + str(count) + '.png')
            count += 1

    os.system('ffmpeg -i ./fov_tiles/%d.png -filter_complex tile=5x5 -y fov.png')
    os.system('ffmpeg -i ./out_fov_tiles/%d.png -filter_complex tile=5x5 -y out_fov.png')


if __name__ == '__main__':
    # cut_pictures()
    combine_pictures()
